package com.qingcloud.df.executor.eventbus;

import akka.actor.ActorRef;
import akka.event.japi.LookupEventBus;
import org.springframework.stereotype.Component;

/**
 * 事件总线
 * @author yangfan
 * @date 2022/1/17 10:39
 */
@Component
public class MessageEventBus extends LookupEventBus<MessageEvent, ActorRef, String> {

    /**
     * 期望的classify数,一般设置为2的n次幂
     */
    @Override
    public int mapSize() {
        return 16;
    }

    @Override
    public int compareSubscribers(ActorRef ref1, ActorRef ref2) {
        return ref1.compareTo(ref2);
    }

    @Override
    public String classify(MessageEvent event) {
        return event.getTopic();
    }

    @Override
    public void publish(MessageEvent event, ActorRef subscriber) {
        subscriber.tell(event, ActorRef.noSender());
    }
}
